package org.jivesoftware.smack.provider;

import java.util.ArrayList;
import org.jivesoftware.smack.packet.DefaultPacketExtension;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Privacy;
import org.jivesoftware.smack.packet.PrivacyItem;
import org.xmlpull.v1.XmlPullParser;

public class PrivacyProvider
  implements IQProvider
{
  public IQ parseIQ(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    Privacy localPrivacy = new Privacy();
    localPrivacy.addExtension(new DefaultPacketExtension(paramXmlPullParser.getName(), paramXmlPullParser.getNamespace()));
    int i = 0;
    while (true)
    {
      int j;
      label149: label172: 
      do
        while (true)
        {
          do
            while (true)
            {
              label101: String str1;
              while (true)
              {
                while (true)
                {
                  String str2;
                  while (true)
                  {
                    if (i != 0)
                      return localPrivacy;
                    j = paramXmlPullParser.next();
                    if (j != 2)
                      break label172;
                    if (!(paramXmlPullParser.getName().equals("active")))
                      break label101;
                    str2 = paramXmlPullParser.getAttributeValue("", "name");
                    if (str2 != null)
                      break;
                    localPrivacy.setDeclineActiveList(true);
                  }
                  localPrivacy.setActiveName(str2);
                }
                if (!(paramXmlPullParser.getName().equals("default")))
                  break label149;
                str1 = paramXmlPullParser.getAttributeValue("", "name");
                if (str1 != null)
                  break;
                localPrivacy.setDeclineDefaultList(true);
              }
              localPrivacy.setDefaultName(str1);
            }
          while (!(paramXmlPullParser.getName().equals("list")));
          parseList(paramXmlPullParser, localPrivacy);
        }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals("query"))));
      i = 1;
    }
  }

  public PrivacyItem parseItem(XmlPullParser paramXmlPullParser)
    throws Exception
  {
    PrivacyItem localPrivacyItem;
    int i = 0;
    String str1 = paramXmlPullParser.getAttributeValue("", "action");
    String str2 = paramXmlPullParser.getAttributeValue("", "order");
    String str3 = paramXmlPullParser.getAttributeValue("", "type");
    boolean bool = true;
    if ("allow".equalsIgnoreCase(str1))
    {
      bool = true;
      localPrivacyItem = new PrivacyItem(str3, bool, Integer.parseInt(str2));
      localPrivacyItem.setValue(paramXmlPullParser.getAttributeValue("", "value"));
    }
    while (true)
    {
      label107: int j;
      label204: 
      do
        while (true)
        {
          do
          {
            while (true)
            {
              do
              {
                if (i == 0)
                  break label107;
                return localPrivacyItem;
              }
              while (!("deny".equalsIgnoreCase(str1)));
              bool = false;
            }
            j = paramXmlPullParser.next();
            if (j != 2)
              break label204;
            if (paramXmlPullParser.getName().equals("iq"))
              localPrivacyItem.setFilterIQ(true);
            if (paramXmlPullParser.getName().equals("message"))
              localPrivacyItem.setFilterMessage(true);
            if (paramXmlPullParser.getName().equals("presence-in"))
              localPrivacyItem.setFilterPresence_in(true);
          }
          while (!(paramXmlPullParser.getName().equals("presence-out")));
          localPrivacyItem.setFilterPresence_out(true);
        }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals("item"))));
      i = 1;
    }
  }

  public void parseList(XmlPullParser paramXmlPullParser, Privacy paramPrivacy)
    throws Exception
  {
    int i = 0;
    String str = paramXmlPullParser.getAttributeValue("", "name");
    ArrayList localArrayList = new ArrayList();
    while (true)
    {
      int j;
      label79: 
      do
        while (true)
        {
          do
          {
            if (i != 0)
            {
              paramPrivacy.setPrivacyList(str, localArrayList);
              return;
            }
            j = paramXmlPullParser.next();
            if (j != 2)
              break label79;
          }
          while (!(paramXmlPullParser.getName().equals("item")));
          localArrayList.add(parseItem(paramXmlPullParser));
        }
      while ((j != 3) || (!(paramXmlPullParser.getName().equals("list"))));
      i = 1;
    }
  }
}